//index.js
//获取应用实例
var app = getApp()

Page({
  data: {
    userName:"",
    pwd:"",
  },
  //事件处理函数

  log: function () {
    var that=this;
    wx.request({
      url: app.globalData.url + 'appletController.do?login',
      data: {
        openid: app.globalData.openid,
        userName:that.data.userName,
        pwd:that.data.pwd
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        app.globalData.userInfo = res.data.data
        console.log(app.globalData.userInfo)
        if (res.data.code == "1000") {
          wx.navigateTo({
            url: '../log/log',
          })
        }
      }
    })
  },
  passWdInput:function(e){
    this.setData({
      pwd: e.detail.value
    })
  },
  usnInput: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },
  onLoad: function (e) {
    wx.login({
      success: function (res) {
        if (res.code) {
          //发起网络请求
          wx.request({
            url: app.globalData.url + 'appletController.do?getOpenid&code=' + res.code,
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              if (res.data.code == '1000') {
                app.globalData.openid = res.data.data;
                wx.request({
                  url: app.globalData.url + 'appletController.do?checkLogin',
                  data: {
                    openid: app.globalData.openid
                  },
                  method: 'GET',
                  header: {
                    'content-type': 'application/json'
                  },
                  success: function (res) {
                    console.log(app.globalData.userInfo)
                    if (res.data.code == "1000") {
                      console.log(res.data)
                      app.globalData.userInfo = res.data.data
                      wx.navigateTo({
                        url: '../log/log',
                      })
                    }
                  }
                })
              }
            }
          })
        } else {
          console.log('获取用户登录态失败！' + res.errMsg)
        }
      }
    });
    
  }
})

